package SimpleLACore

import Instructions._
import Consts._

object decode {
  val invalidInst = List(N, N, OP1_X, OP2_X, alu_X, WB_X, WB_R0, M_X, MT_X, N, N, N, tlb_X, N, N, BR_N, N, N)
  val decodeTable =
    Array(//       valid, plv,                                                         CSR,brk,sysCall   ertn,idle     cacop preld
      RDCNTIDW -> List(Y, N, OP1_X  , OP2_X   , alu_X    , WB_CNTID, WB_RJ, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      RDCNTVLW -> List(Y, N, OP1_X  , OP2_X   , alu_X    , WB_CNTVL, WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      RDCNTVHW -> List(Y, N, OP1_X  , OP2_X   , alu_X    , WB_CNTVH, WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      ADDW     -> List(Y, N, OP1_rj , OP2_rk  , alu_ADD  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SUBW     -> List(Y, N, OP1_rj , OP2_rk  , alu_SUB  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SLT      -> List(Y, N, OP1_rj , OP2_rk  , alu_SLT  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SLTU     -> List(Y, N, OP1_rj , OP2_rk  , alu_SLTU , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      NOR      -> List(Y, N, OP1_rj , OP2_rk  , alu_NOR  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      AND      -> List(Y, N, OP1_rj , OP2_rk  , alu_AND  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      OR       -> List(Y, N, OP1_rj , OP2_rk  , alu_OR   , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      XOR      -> List(Y, N, OP1_rj , OP2_rk  , alu_XOR  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SLLW     -> List(Y, N, OP1_rj , OP2_rk  , alu_SLL  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SRLW     -> List(Y, N, OP1_rj , OP2_rk  , alu_SRL  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SRAW     -> List(Y, N, OP1_rj , OP2_rk  , alu_SRA  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      MULW     -> List(Y, N, OP1_rj , OP2_rk  , alu_MUL  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      MULHW    -> List(Y, N, OP1_rj , OP2_rk  , alu_MULH , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      MULHWU   -> List(Y, N, OP1_rj , OP2_rk  , alu_MULHU, WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      DIVW     -> List(Y, N, OP1_rj , OP2_rk  , alu_DIV  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      MODW     -> List(Y, N, OP1_rj , OP2_rk  , alu_MOD  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      DIVWU    -> List(Y, N, OP1_rj , OP2_rk  , alu_DIVU , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      MODWU    -> List(Y, N, OP1_rj , OP2_rk  , alu_MODU , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      BREAK    -> List(Y, N, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, Y, N, tlb_X   , N, N, BR_N  , N, N),
      SYSCALL  -> List(Y, N, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, Y, tlb_X   , N, N, BR_N  , N, N),
      SLLIW    -> List(Y, N, OP1_rj , OP2_k   , alu_SLL  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SRLIW    -> List(Y, N, OP1_rj , OP2_k   , alu_SRL  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SRAIW    -> List(Y, N, OP1_rj , OP2_k   , alu_SRA  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SLTI     -> List(Y, N, OP1_rj , OP2_si12, alu_SLT  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SLTUI    -> List(Y, N, OP1_rj , OP2_si12, alu_SLTU , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      ADDIW    -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      ANDI     -> List(Y, N, OP1_rj , OP2_ui12, alu_AND  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      ORI      -> List(Y, N, OP1_rj , OP2_ui12, alu_OR   , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      XORI     -> List(Y, N, OP1_rj , OP2_ui12, alu_XOR  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
    //CSRRD    -> List(Y, N, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
    //CSRWR    -> List(Y, N, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      CSRXCHG  -> List(Y, Y, OP1_X  , OP2_X   , alu_X    , WB_CSR  , WB_RD, M_X , MT_X , Y, N, N, tlb_X   , N, N, BR_N  , N, N),
      CACOP    -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_X    , WB_R0, M_LD, MT_B , N, N, N, tlb_X   , N, N, BR_N  , Y, N),
      TLBSRCH  -> List(Y, Y, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_srch, N, N, BR_N  , N, N),
      TLBRD    -> List(Y, Y, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_rd  , N, N, BR_N  , N, N),
      TLBWR    -> List(Y, Y, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_wr  , N, N, BR_N  , N, N),
      TLBFILL  -> List(Y, Y, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_fill, N, N, BR_N  , N, N),
      INVTLB   -> List(Y, Y, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_inv , N, N, BR_N  , N, N),
      ERTN     -> List(Y, Y, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , Y, N, BR_N  , N, N),
      IDLE     -> List(Y, Y, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, Y, BR_N  , N, N),
      LU12IW   -> List(Y, N, OP1_X  , OP2_ui20, alu_COPY , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      PCADDU12I-> List(Y, N, OP1_PC , OP2_ui20, alu_ADD  , WB_ALU  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      LLW      -> List(Y, N, OP1_rj , OP2_si14, alu_ADD  , WB_MEM  , WB_RD, M_LL, MT_W , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      SCW      -> List(Y, N, OP1_rj , OP2_si14, alu_ADD  , WB_LLB  , WB_RD, M_SC, MT_W , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      LDB      -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_MEM  , WB_RD, M_LD, MT_B , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      LDH      -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_MEM  , WB_RD, M_LD, MT_H , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      LDW      -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_MEM  , WB_RD, M_LD, MT_W , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      STB      -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_X    , WB_R0, M_ST, MT_B , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      STH      -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_X    , WB_R0, M_ST, MT_H , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      STW      -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_X    , WB_R0, M_ST, MT_W , N, N, N, tlb_X   , N, N, BR_N  , N, N),
      LDBU     -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_MEM  , WB_RD, M_LD, MT_BU, N, N, N, tlb_X   , N, N, BR_N  , N, N),
      LDHU     -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_MEM  , WB_RD, M_LD, MT_HU, N, N, N, tlb_X   , N, N, BR_N  , N, N),
      PRELD    -> List(Y, N, OP1_rj , OP2_si12, alu_ADD  , WB_X    , WB_R0, M_LD, MT_B , N, N, N, tlb_X   , N, N, BR_N  , N, Y),
      DBAR     -> List(Y, N, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),//nop
      IBAR     -> List(Y, N, OP1_X  , OP2_X   , alu_X    , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_N  , N, N),//nop
      JIRL     -> List(Y, N, OP1_rj , OP2_of16, alu_ADD  , WB_PC4  , WB_RD, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_B  , N, N),
      B        -> List(Y, N, OP1_PC , OP2_of26, alu_ADD  , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_B  , N, N),
      BL       -> List(Y, N, OP1_PC , OP2_of26, alu_ADD  , WB_PC4  , WB_R1, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_B  , N, N),
      BEQ      -> List(Y, N, OP1_PC , OP2_of16, alu_ADD  , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_EQ , N, N),
      BNE      -> List(Y, N, OP1_PC , OP2_of16, alu_ADD  , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_NE , N, N),
      BLT      -> List(Y, N, OP1_PC , OP2_of16, alu_ADD  , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_LT , N, N),
      BGE      -> List(Y, N, OP1_PC , OP2_of16, alu_ADD  , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_GE , N, N),
      BLTU     -> List(Y, N, OP1_PC , OP2_of16, alu_ADD  , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_LTU, N, N),
      BGEU     -> List(Y, N, OP1_PC , OP2_of16, alu_ADD  , WB_X    , WB_R0, M_X , MT_X , N, N, N, tlb_X   , N, N, BR_GEU, N, N),
    )

}
